package com.ruoyi.web.controller.factory;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFactory;
import com.ruoyi.system.service.ISysFactoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 厂家管理Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@RestController
@RequestMapping("/system/factory")
public class SysFactoryController extends BaseController
{
    @Autowired
    private ISysFactoryService sysFactoryService;

    /**
     * 查询厂家管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFactory sysFactory)
    {
        startPage();
        List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
        return getDataTable(list);
    }

    /**
     * 导出厂家管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:factory:export')")
    @Log(title = "厂家管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysFactory sysFactory)
    {
        List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
        ExcelUtil<SysFactory> util = new ExcelUtil<SysFactory>(SysFactory.class);
        return util.exportExcel(list, "厂家管理数据");
    }

    /**
     * 获取厂家管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:factory:query')")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable("factoryId") Integer factoryId)
    {
        return AjaxResult.success(sysFactoryService.selectSysFactoryByFactoryId(factoryId));
    }

    /**
     * 新增厂家管理
     */
    @PreAuthorize("@ss.hasPermi('system:factory:add')")
    @Log(title = "厂家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFactory sysFactory)
    {
        return toAjax(sysFactoryService.insertSysFactory(sysFactory));
    }

    /**
     * 修改厂家管理
     */
    @PreAuthorize("@ss.hasPermi('system:factory:edit')")
    @Log(title = "厂家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFactory sysFactory)
    {
        return toAjax(sysFactoryService.updateSysFactory(sysFactory));
    }

    /**
     * 删除厂家管理
     */
    @PreAuthorize("@ss.hasPermi('system:factory:remove')")
    @Log(title = "厂家管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Integer[] factoryIds)
    {
        return toAjax(sysFactoryService.deleteSysFactoryByFactoryIds(factoryIds));
    }

    @GetMapping("/allfactory")
    @ResponseBody
    public List<SysFactory> getAllfactory(SysFactory sysFactory ){
        return sysFactoryService.selectSysFactoryList(sysFactory);
    }

}
